#include"SMAC.h"

inline int SMAC::get_delay() {
    return this->delay_cycles;
}

void SMAC::input_operands(std::vector<base_operand*>* operands) {
    this->operand_list = operands;
}

inline uint64_t SMAC::read_Reg(int reg_id) {
    std::cout << "Reading register ID: " << reg_id << std::endl;
    if (this->RF == nullptr) {
        std::cerr << "Error: RegisterFile pointer is null!" << std::endl;
        return 0.0; // 或者抛出异常
    }
    // std::cout << "RegisterFile pointer is " << this->RF << std::endl;
    return this->RF->get_register_value(reg_id);
}

inline void SMAC::write_Reg(int reg_id, uint64_t value, int delay) {
    // return set_vec_regsiter_single(reg_id, this->id, Salue);
    this->res_value = value;
    this->dst_reg_id = reg_id;
    this->delay_cycles = delay;
}

inline bool is_Vec_Addr_Reg(int reg_id) {
    //AR0~AR7, OR0~OR7代表是VARF，否则为SARF
    if ((reg_id >= AR0 && reg_id <= AR7) || (reg_id >= OR0 && reg_id <= OR7)) {
        return true;
    } else {
        return false;
    }
}


inline uint64_t SMAC::do_SFMULD(int src1_reg_id, int src2_reg_id, int dst_reg_id) {
    uint64_t res = double_to_uint64(uint64_to_double(read_Reg(src1_reg_id)) * uint64_to_double(read_Reg(src2_reg_id)));
    write_Reg(dst_reg_id, res, 4);
    //!将结果的64位值返回的作用是预留后续的性能分析API，用以获取DSP执行过程中的细粒度数据
    return res;
}


inline uint64_t SMAC::do_SFMULS32(int src1_reg_id, int src2_reg_id, int dst_reg_id) {

    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    float low32_src1 = uint32_to_float(src1 & 0xFFFFFFFF);
    float high32_src1 = uint32_to_float((src1 >> 32) & 0xFFFFFFFF);
    float low32_src2 = uint32_to_float(src2 & 0xFFFFFFFF);
    float high32_src2 = uint32_to_float((src2 >> 32) & 0xFFFFFFFF); //取高、低32位

    float res_low = low32_src1 * low32_src2;
    float res_high =high32_src1 * high32_src2;

    uint32_t res_low_uint = float_to_uint32(res_low);
    uint32_t res_high_uint = float_to_uint32(res_high);

    uint64_t res = (static_cast<uint64_t>(res_high_uint) << 32) | static_cast<uint64_t>(res_low_uint);

    write_Reg(dst_reg_id, res, 4);
    return res;
}


inline uint64_t SMAC::do_SFMULAD(int src1_reg_id, int src2_reg_id, int src3_reg_id, int dst_reg_id) {
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    uint64_t src3 = read_Reg(src3_reg_id);

    double d_src1 = uint64_to_double(src1);
    double d_src2 = uint64_to_double(src2);
    double d_src3 = uint64_to_double(src3);

    uint64_t res = double_to_uint64(d_src1 * d_src2 + d_src3);

    return res;
}


inline uint64_t SMAC::do_SFMULAS32(int src1_reg_id, int src2_reg_id, int src3_reg_id, int dst_reg_id) {

    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    uint64_t src3 = read_Reg(src3_reg_id);

    float low32_src1 = uint32_to_float(src1 & 0xFFFFFFFF);
    float high32_src1 = uint32_to_float((src1 >> 32) & 0xFFFFFFFF);
    float low32_src2 = uint32_to_float(src2 & 0xFFFFFFFF);
    float high32_src2 = uint32_to_float((src2 >> 32) & 0xFFFFFFFF);
    float low32_src3 = uint32_to_float(src3 & 0xFFFFFFFF);
    float high32_src3 = uint32_to_float((src3 >> 32) & 0xFFFFFFFF); //取高、低32位
    
    float res_low = low32_src1 * low32_src2 + low32_src3;
    float res_high = high32_src1 * high32_src2 + high32_src3;

    uint32_t res_low_uint = float_to_uint32(res_low);
    uint32_t res_high_uint = float_to_uint32(res_high);

    uint64_t res = (static_cast<uint64_t>(res_high_uint) << 32) | static_cast<uint64_t>(res_low_uint);

    write_Reg(dst_reg_id, res, 6);
    return res;
}


inline uint64_t SMAC::do_SFMULBD(int src1_reg_id, int src2_reg_id, int src3_reg_id, int dst_reg_id) {
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    uint64_t src3 = read_Reg(src3_reg_id);

    double d_src1 = uint64_to_double(src1);
    double d_src2 = uint64_to_double(src2);
    double d_src3 = uint64_to_double(src3);
    uint64_t res = double_to_uint64(d_src1 * d_src2 - d_src3);

    write_Reg(dst_reg_id, res, 6);

    return res;
}

inline uint64_t SMAC::do_SFMULBS32(int src1_reg_id, int src2_reg_id, int src3_reg_id, int dst_reg_id) {
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    uint64_t src3 = read_Reg(src3_reg_id);

    float low32_src1 = uint32_to_float(src1 & 0xFFFFFFFF);
    float high32_src1 = uint32_to_float((src1 >> 32) & 0xFFFFFFFF);
    float low32_src2 = uint32_to_float(src2 & 0xFFFFFFFF);
    float high32_src2 = uint32_to_float((src2 >> 32) & 0xFFFFFFFF);
    float low32_src3 = uint32_to_float(src3 & 0xFFFFFFFF);
    float high32_src3 = uint32_to_float((src3 >> 32) & 0xFFFFFFFF); //取高、低32位
    
    float res_low = low32_src1 * low32_src2 - low32_src3;
    float res_high = high32_src1 * high32_src2 - high32_src3;

    uint32_t res_low_uint = float_to_uint32(res_low);
    uint32_t res_high_uint = float_to_uint32(res_high);

    uint64_t res = (static_cast<uint64_t>(res_high_uint) << 32) | static_cast<uint64_t>(res_low_uint);

    write_Reg(dst_reg_id, res, 6);
    return res;
}


inline uint64_t SMAC::do_SFDOT32(int src1_reg_id, int src2_reg_id, int dst_reg_id) {

    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF; //取高、低32位

    float res_f = uint32_to_float(high32_src1) * uint32_to_float(high32_src2) + uint32_to_float(low32_src1) * uint32_to_float(low32_src2);
    uint64_t res = 0;
    std::memcpy(&res, &res_f, sizeof(res)); // 安全转换

    write_Reg(dst_reg_id, res, 6);
    return res;
}


inline uint64_t SMAC::do_SFCREAL32(int src1_reg_id, int src2_reg_id, int dst_reg_id) {

    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF; //取高、低32位
    float res_f;

    #if ENDIAN == 1
        res_f = uint32_to_float(low32_src1) * uint32_to_float(low32_src2) - uint32_to_float(high32_src1) * uint32_to_float(high32_src2);
    #else
        res_f = uint32_to_float(high32_src1) * uint32_to_float(high32_src2) - uint32_to_float(low32_src1) * uint32_to_float(low32_src2);
    #endif
    uint64_t res = 0;
    std::memcpy(&res, &res_f, sizeof(res)); // 安全转换
    
    write_Reg(dst_reg_id, res, 6);
    return res;
}


inline uint64_t SMAC::do_SFCIMAG32(int src1_reg_id, int src2_reg_id, int dst_reg_id) {

    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF; //取高、低32位

    float res_f = uint32_to_float(low32_src1) *  uint32_to_float(high32_src2) + uint32_to_float(high32_src1) * uint32_to_float(low32_src2);
    uint64_t res = 0;
    std::memcpy(&res, &res_f, sizeof(res)); // 安全转换
    
    write_Reg(dst_reg_id, res, 6);
    return res;
}


inline uint64_t SMAC::do_SFADDH16(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    float ll_src1 = fp16_to_float(src1 & 0xFFFF);
    float lh_src1 = fp16_to_float((src1 >> 16) & 0xFFFF);
    float hl_src1 = fp16_to_float((src1 >> 32) & 0xFFFF);
    float hh_src1 = fp16_to_float((src1 >> 48) & 0xFFFF);
    float ll_src2 = fp16_to_float(src2 & 0xFFFF);
    float lh_src2 = fp16_to_float((src2 >> 16) & 0xFFFF);
    float hl_src2 = fp16_to_float((src2 >> 32) & 0xFFFF);
    float hh_src2 = fp16_to_float((src2 >> 48) & 0xFFFF); //每16位取一个半精度浮点数

    //!使用uint64_t存储由float计算后转化为uint16_t的结果，用于后续拼接操作
    uint64_t res_hh, res_hl, res_lh, res_ll;
    res_hh = float_to_fp16(hh_src1 + hh_src2);
    res_hl = float_to_fp16(hl_src1 + hl_src2);
    res_lh = float_to_fp16(lh_src1 + lh_src2);
    res_ll = float_to_fp16(ll_src1 + ll_src2);
    
    uint64_t res = ((res_hh & 0xFFFF) << 48) | ((res_hl & 0xFFFF) << 32) | ((res_lh & 0xFFFF) << 16) | (res_ll & 0xFFFF);

    write_Reg(dst_reg_id, res, 4);
    return res;
}


inline uint64_t SMAC::do_SFSUBH16(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t ll_src1 = src1 & 0xFFFF;
    uint64_t lh_src1 = (src1 >> 16) & 0xFFFF;
    uint64_t hl_src1 = (src1 >> 32) & 0xFFFF;
    uint64_t hh_src1 = (src1 >> 48) & 0xFFFF;
    uint64_t ll_src2 = src2 & 0xFFFF;
    uint64_t lh_src2 = (src2 >> 16) & 0xFFFF;
    uint64_t hl_src2 = (src2 >> 32) & 0xFFFF;
    uint64_t hh_src2 = (src2 >> 48) & 0xFFFF; //每16位取一个半精度浮点数
    
    float res_hh, res_hl, res_lh, res_ll;
    res_hh = fp16_to_float(hh_src2) - fp16_to_float(hh_src1);
    res_hl = fp16_to_float(hl_src2) - fp16_to_float(hl_src1);
    res_lh = fp16_to_float(lh_src2) - fp16_to_float(lh_src1);
    res_ll = fp16_to_float(ll_src2) - fp16_to_float(ll_src1);
    uint64_t res_hh_64, res_hl_64, res_lh_64, res_ll_64;
    res_hh_64 = float_to_fp16(res_hh);
    res_hl_64 = float_to_fp16(res_hl);
    res_lh_64 = float_to_fp16(res_lh);
    res_ll_64 = float_to_fp16(res_ll);

    uint64_t res = (res_hh_64 << 48) | (res_hl_64 << 32) | (res_lh_64 << 16) | res_ll_64;

    write_Reg(dst_reg_id, res, 4);
    return res;
}



inline uint64_t SMAC::do_SFMULH16(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t ll_src1 = src1 & 0xFFFF;
    uint64_t lh_src1 = (src1 >> 16) & 0xFFFF;
    uint64_t hl_src1 = (src1 >> 32) & 0xFFFF;
    uint64_t hh_src1 = (src1 >> 48) & 0xFFFF;
    uint64_t ll_src2 = src2 & 0xFFFF;
    uint64_t lh_src2 = (src2 >> 16) & 0xFFFF;
    uint64_t hl_src2 = (src2 >> 32) & 0xFFFF;
    uint64_t hh_src2 = (src2 >> 48) & 0xFFFF; //每16位取一个半精度浮点数
    
    float res_hh, res_hl, res_lh, res_ll;
    res_hh = fp16_to_float(hh_src1) * fp16_to_float(hh_src2);
    res_hl = fp16_to_float(hl_src1) * fp16_to_float(hl_src2);
    res_lh = fp16_to_float(lh_src1) * fp16_to_float(lh_src2);
    res_ll = fp16_to_float(ll_src1) * fp16_to_float(ll_src2);

    uint64_t res_hh_64, res_hl_64, res_lh_64, res_ll_64;
    res_hh_64 = float_to_fp16(res_hh);
    res_hl_64 = float_to_fp16(res_hl);
    res_lh_64 = float_to_fp16(res_lh);
    res_ll_64 = float_to_fp16(res_ll);
    
    uint64_t res = ((res_hh_64 & 0xFFFF) << 48) | ((res_hl_64 & 0xFFFF) << 32) | ((res_lh_64 & 0xFFFF) << 16) | (res_ll_64 & 0xFFFF);

    write_Reg(dst_reg_id, res, 4);
    return res;
}


inline uint64_t SMAC::do_SFMULAH16(int src1_reg_id, int src2_reg_id, int src3_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    uint64_t src3 = read_Reg(src3_reg_id);

    uint64_t ll_src1 = src1 & 0xFFFF;
    uint64_t lh_src1 = (src1 >> 16) & 0xFFFF;
    uint64_t hl_src1 = (src1 >> 32) & 0xFFFF;
    uint64_t hh_src1 = (src1 >> 48) & 0xFFFF;
    uint64_t ll_src2 = src2 & 0xFFFF;
    uint64_t lh_src2 = (src2 >> 16) & 0xFFFF;
    uint64_t hl_src2 = (src2 >> 32) & 0xFFFF;
    uint64_t hh_src2 = (src2 >> 48) & 0xFFFF;
    uint64_t ll_src3 = src3 & 0xFFFF;
    uint64_t lh_src3 = (src3 >> 16) & 0xFFFF;
    uint64_t hl_src3 = (src3 >> 32) & 0xFFFF;
    uint64_t hh_src3 = (src3 >> 48) & 0xFFFF; //每16位取一个半精度浮点数
    
    float res_hh, res_hl, res_lh, res_ll;
    res_hh = fp16_to_float(hh_src1) * fp16_to_float(hh_src2) + fp16_to_float(hh_src3);
    res_hl = fp16_to_float(hl_src1) * fp16_to_float(hl_src2) + fp16_to_float(hl_src3);
    res_lh = fp16_to_float(lh_src1) * fp16_to_float(lh_src2) + fp16_to_float(lh_src3);
    res_ll = fp16_to_float(ll_src1) * fp16_to_float(ll_src2) + fp16_to_float(ll_src3);
    
    uint64_t res_hh_64, res_hl_64, res_lh_64, res_ll_64;
    res_hh_64 = float_to_fp16(res_hh);
    res_hl_64 = float_to_fp16(res_hl);
    res_lh_64 = float_to_fp16(res_lh);
    res_ll_64 = float_to_fp16(res_ll);

    uint64_t res = ((res_hh_64 & 0xFFFF) << 48) | ((res_hl_64 & 0xFFFF) << 32) | ((res_lh_64 & 0xFFFF) << 16) | (res_ll_64 & 0xFFFF);

    write_Reg(dst_reg_id, res, 6);
    return res;
}


inline uint64_t SMAC::do_SFMULBH16(int src1_reg_id, int src2_reg_id, int src3_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    uint64_t src3 = read_Reg(src3_reg_id);

    uint64_t ll_src1 = src1 & 0xFFFF;
    uint64_t lh_src1 = (src1 >> 16) & 0xFFFF;
    uint64_t hl_src1 = (src1 >> 32) & 0xFFFF;
    uint64_t hh_src1 = (src1 >> 48) & 0xFFFF;
    uint64_t ll_src2 = src2 & 0xFFFF;
    uint64_t lh_src2 = (src2 >> 16) & 0xFFFF;
    uint64_t hl_src2 = (src2 >> 32) & 0xFFFF;
    uint64_t hh_src2 = (src2 >> 48) & 0xFFFF;
    uint64_t ll_src3 = src3 & 0xFFFF;
    uint64_t lh_src3 = (src3 >> 16) & 0xFFFF;
    uint64_t hl_src3 = (src3 >> 32) & 0xFFFF;
    uint64_t hh_src3 = (src3 >> 48) & 0xFFFF; //每16位取一个半精度浮点数
    
    float res_hh, res_hl, res_lh, res_ll;
    res_hh = float_to_fp16(hh_src1) * float_to_fp16(hh_src2) - float_to_fp16(hh_src3);
    res_hl = float_to_fp16(hl_src1) * float_to_fp16(hl_src2) - float_to_fp16(hl_src3);
    res_lh = float_to_fp16(lh_src1) * float_to_fp16(lh_src2) - float_to_fp16(lh_src3);
    res_ll = float_to_fp16(ll_src1) * float_to_fp16(ll_src2) - float_to_fp16(ll_src3);

    uint64_t res_hh_64, res_hl_64, res_lh_64, res_ll_64;
    res_hh_64 = float_to_fp16(res_hh);
    res_hl_64 = float_to_fp16(res_hl);
    res_lh_64 = float_to_fp16(res_lh);
    res_ll_64 = float_to_fp16(res_ll);
    
    uint64_t res = ((res_hh_64 & 0xFFFF) << 48) | ((res_hl_64 & 0xFFFF) << 32) | ((res_lh_64 & 0xFFFF) << 16) | (res_ll_64 & 0xFFFF);

    write_Reg(dst_reg_id, res, 6);
    return res;
}


inline uint64_t SMAC::do_SFCMPEH16(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t ll_src1 = src1 & 0xFFFF;
    uint64_t lh_src1 = (src1 >> 16) & 0xFFFF;
    uint64_t hl_src1 = (src1 >> 32) & 0xFFFF;
    uint64_t hh_src1 = (src1 >> 48) & 0xFFFF;
    uint64_t ll_src2 = src2 & 0xFFFF;
    uint64_t lh_src2 = (src2 >> 16) & 0xFFFF;
    uint64_t hl_src2 = (src2 >> 32) & 0xFFFF;
    uint64_t hh_src2 = (src2 >> 48) & 0xFFFF; //每16位取一个半精度浮点数
    
    uint64_t res_hh, res_hl, res_lh, res_ll;
    if (hh_src1 == hh_src2){
        res_hh = 0001;
    }else if (hl_src1 == hl_src2){
        res_hl = 0001;
    }else if (lh_src1 == lh_src2){
        res_lh = 0001;
    }else if (ll_src1 == ll_src2){
        res_ll = 0001;
    }
    
    uint64_t res = (res_hh << 12) | (res_hl << 8) | (res_lh  << 4) | res_ll;


    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFCMPGH16(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t ll_src1 = src1 & 0xFFFF;
    uint64_t lh_src1 = (src1 >> 16) & 0xFFFF;
    uint64_t hl_src1 = (src1 >> 32) & 0xFFFF;
    uint64_t hh_src1 = (src1 >> 48) & 0xFFFF;
    uint64_t ll_src2 = src2 & 0xFFFF;
    uint64_t lh_src2 = (src2 >> 16) & 0xFFFF;
    uint64_t hl_src2 = (src2 >> 32) & 0xFFFF;
    uint64_t hh_src2 = (src2 >> 48) & 0xFFFF; //每16位取一个半精度浮点数
    
    uint64_t res_hh, res_hl, res_lh, res_ll;
    if (hh_src2 > hh_src1){
        res_hh = 0001;
    }else if (hl_src2 > hl_src1){
        res_hl = 0001;
    }else if (lh_src2 > lh_src1){
        res_lh = 0001;
    }else if (ll_src2 > ll_src1){
        res_ll = 0001;
    }
    
    
    uint64_t res = (res_hh << 12) | (res_hl << 8) | (res_lh  << 4) | res_ll;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFCMPLH16(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t ll_src1 = src1 & 0xFFFF;
    uint64_t lh_src1 = (src1 >> 16) & 0xFFFF;
    uint64_t hl_src1 = (src1 >> 32) & 0xFFFF;
    uint64_t hh_src1 = (src1 >> 48) & 0xFFFF;
    uint64_t ll_src2 = src2 & 0xFFFF;
    uint64_t lh_src2 = (src2 >> 16) & 0xFFFF;
    uint64_t hl_src2 = (src2 >> 32) & 0xFFFF;
    uint64_t hh_src2 = (src2 >> 48) & 0xFFFF; //每16位取一个半精度浮点数
    
    uint64_t res_hh, res_hl, res_lh, res_ll;
    if (hh_src2 < hh_src1){
        res_hh = 0001;
    }else if (hl_src2 < hl_src1){
        res_hl = 0001;
    }else if (lh_src2 < lh_src1){
        res_lh = 0001;
    }else if (ll_src2 < ll_src1){
        res_ll = 0001;
    }
    
    
    uint64_t res = (res_hh << 12) | (res_hl << 8) | (res_lh  << 4) | res_ll;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFHINT16(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t ll_src = src & 0xFFFF;
    uint64_t lh_src = (src >> 16) & 0xFFFF;
    uint64_t hl_src = (src >> 32) & 0xFFFF;
    uint64_t hh_src = (src >> 48) & 0xFFFF; //每16位取一个半精度浮点数

    float ll_src_f = fp16_to_float(ll_src);
    float lh_src_f = fp16_to_float(lh_src);
    float hl_src_f = fp16_to_float(hl_src);
    float hh_src_f = fp16_to_float(hh_src);

    uint64_t res_hh = static_cast<uint64_t>(static_cast<int16_t>(std::round(hh_src_f)));
    uint64_t res_hl = static_cast<uint64_t>(static_cast<int16_t>(std::round(hl_src_f)));
    uint64_t res_lh = static_cast<uint64_t>(static_cast<int16_t>(std::round(lh_src_f)));
    uint64_t res_ll = static_cast<uint64_t>(static_cast<int16_t>(std::round(ll_src_f)));
    
    uint64_t res = (res_hh << 48) | (res_hl << 32) | (res_lh << 16) | res_ll;

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFHTRU16(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t ll_src = src & 0xFFFF;
    uint64_t lh_src = (src >> 16) & 0xFFFF;
    uint64_t hl_src = (src >> 32) & 0xFFFF;
    uint64_t hh_src = (src >> 48) & 0xFFFF; //每16位取一个半精度浮点数
    
    uint64_t res_hh, res_hl, res_lh, res_ll;
    res_hh = static_cast<uint64_t>(std::floor(fp16_to_float(hh_src)));
    res_hl = static_cast<uint64_t>(std::floor(fp16_to_float(hl_src)));
    res_lh = static_cast<uint64_t>(std::floor(fp16_to_float(lh_src)));
    res_ll = static_cast<uint64_t>(std::floor(fp16_to_float(ll_src)));
    
    uint64_t res = ((res_hh & 0xFFFF) << 48) | ((res_hl & 0xFFFF) << 32) | ((res_lh & 0xFFFF) << 16) | (res_ll & 0xFFFF);

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFINTH16(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    int16_t ll_src = static_cast<uint16_t>(src & 0xFFFF);
    int16_t lh_src = static_cast<uint16_t>((src >> 16) & 0xFFFF);
    int16_t hl_src = static_cast<uint16_t>((src >> 32) & 0xFFFF);
    int16_t hh_src = static_cast<uint16_t>((src >> 48) & 0xFFFF); //每16位取一个半精度浮点数
    
    uint64_t res_hh, res_hl, res_lh, res_ll;
    res_hh = static_cast<uint64_t>(float_to_fp16(int16_to_float(hh_src)));
    res_hl = static_cast<uint64_t>(float_to_fp16(int16_to_float(hl_src)));
    res_lh = static_cast<uint64_t>(float_to_fp16(int16_to_float(lh_src)));
    res_ll = static_cast<uint64_t>(float_to_fp16(int16_to_float(ll_src)));
    
    uint64_t res = (res_hh << 48) | (res_hl << 32) | (res_lh << 16) | res_ll;

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFINTHU16(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t ll_src = src & 0xFFFF;
    uint64_t lh_src = (src >> 16) & 0xFFFF;
    uint64_t hl_src = (src >> 32) & 0xFFFF;
    uint64_t hh_src = (src >> 48) & 0xFFFF;//每16位取一个半精度浮点数
    
    uint64_t res_hh, res_hl, res_lh, res_ll;
    res_hh = float_to_fp16(fp16_to_float(hh_src));
    res_hl = float_to_fp16(fp16_to_float(hl_src));
    res_lh = float_to_fp16(fp16_to_float(lh_src));
    res_ll = float_to_fp16(fp16_to_float(ll_src));
    
    uint64_t res = (res_hh << 48) | (res_hl << 32) | (res_lh << 16) | res_ll;

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFSPHP16(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF;
    
    uint64_t res_hh, res_hl, res_lh, res_ll;
    res_hh = float_to_fp16(uint32_to_float(high32_src2));
    res_hl = float_to_fp16(uint32_to_float(low32_src2));
    res_lh = float_to_fp16(uint32_to_float(high32_src1));
    res_ll = float_to_fp16(uint32_to_float(low32_src1));
    
    uint64_t res = ((res_hh & 0xFFFF) << 48) | ((res_hl & 0xFFFF) << 32) | ((res_lh & 0xFFFF) << 16) | (res_ll & 0xFFFF);

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFHPSP16L(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t ll_src = src & 0xFFFF;
    uint64_t lh_src = (src >> 16) & 0xFFFF;//低半字中，每16位取一个半精度浮点数
 
    
    uint64_t res_high, res_low;
    res_high = float_to_uint32(fp16_to_float(lh_src));
    res_low = float_to_uint32(fp16_to_float(ll_src));
    
    uint64_t res = res_high << 32 | res_low;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFHPSP16H(int src_reg_id, int dst_reg_id){
     uint64_t src = read_Reg(src_reg_id);

    uint64_t hl_src = (src >> 32) & 0xFFFF;
    uint64_t hh_src = (src >> 48) & 0xFFFF; //高半字中，每16位取一个半精度浮点数
 
    
    uint64_t res_high, res_low;
    res_high = float_to_uint32(fp16_to_float(hh_src));
    res_low = float_to_uint32(static_cast<float>(hl_src));
    
    uint64_t res = res_high << 32 | res_low;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFMANH16(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint16_t ll_src = static_cast<uint16_t>(src & 0xFFFF);
    uint16_t lh_src = static_cast<uint16_t>((src >> 16) & 0xFFFF);
    uint16_t hl_src = static_cast<uint16_t>((src >> 32) & 0xFFFF);
    uint16_t hh_src = static_cast<uint16_t>((src >> 48) & 0xFFFF); //每16位取一个半精度浮点数

    uint64_t res_hh, res_hl, res_lh, res_ll;
    res_hh = fraction_16(hh_src);
    res_hl = fraction_16(hl_src);
    res_lh = fraction_16(lh_src);
    res_ll = fraction_16(ll_src);

    uint64_t res = ((res_hh & 0xFFFF) << 48) | ((res_hl & 0xFFFF) << 32) | ((res_lh & 0xFFFF) << 16) | (res_ll & 0xFFFF);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFLOGH16(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint16_t ll_src = static_cast<uint16_t>(src & 0xFFFF);
    uint16_t lh_src = static_cast<uint16_t>((src >> 16) & 0xFFFF);
    uint16_t hl_src = static_cast<uint16_t>((src >> 32) & 0xFFFF);
    uint16_t hh_src = static_cast<uint16_t>((src >> 48) & 0xFFFF); //每16位取一个半精度浮点数

    uint64_t res_ll, res_lh, res_hl, res_hh;
    res_ll = exponent(ll_src);
    res_lh = exponent(lh_src);
    res_hl = exponent(hl_src);
    res_hh = exponent(hh_src);

    uint64_t res = ((res_hh & 0xFFFF) << 48) | ((res_hl & 0xFFFF) << 32) | ((res_lh & 0xFFFF) << 16) | (res_ll & 0xFFFF);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFABSH16(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint16_t ll_src = static_cast<uint16_t>(src & 0xFFFF);
    uint16_t lh_src = static_cast<uint16_t>((src >> 16) & 0xFFFF);
    uint16_t hl_src = static_cast<uint16_t>((src >> 32) & 0xFFFF);
    uint16_t hh_src = static_cast<uint16_t>((src >> 48) & 0xFFFF); //每16位取一个半精度浮点数

    float res_ll_f, res_lh_f, res_hl_f, res_hh_f;
    res_ll_f = fp16_to_float(ll_src);
    res_lh_f = fp16_to_float(lh_src);
    res_hl_f = fp16_to_float(hl_src);
    res_hh_f = fp16_to_float(hh_src);

    uint64_t res_ll, res_lh, res_hl, res_hh;
    res_ll = float_to_fp16(fabs(res_ll_f));
    res_lh = float_to_fp16(fabs(res_lh_f));
    res_hl = float_to_fp16(fabs(res_hl_f));
    res_hh = float_to_fp16(fabs(res_hh_f));

    uint64_t res = ((res_hh & 0xFFFF) << 48) | ((res_hl & 0xFFFF) << 32) | ((res_lh & 0xFFFF) << 16) | (res_ll & 0xFFFF);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFMAX16(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t ll_src1 = src1 & 0xFFFF;
    uint64_t lh_src1 = (src1 >> 16) & 0xFFFF;
    uint64_t hl_src1 = (src1 >> 32) & 0xFFFF;
    uint64_t hh_src1 = (src1 >> 48) & 0xFFFF; 
    uint64_t ll_src2 = src2 & 0xFFFF;
    uint64_t lh_src2 = (src2 >> 16) & 0xFFFF;
    uint64_t hl_src2 = (src2 >> 32) & 0xFFFF;
    uint64_t hh_src2 = (src2 >> 48) & 0xFFFF;//每16位取一个半精度浮点数

    uint64_t res_ll, res_lh, res_hl, res_hh;

    if(fp16_to_float(ll_src1) > fp16_to_float(ll_src2)){
        res_ll = ll_src1;
    }else{
        res_ll = ll_src2;
    }
    if(fp16_to_float(lh_src1) > fp16_to_float(lh_src2)){
        res_lh = lh_src1;
    }else{
        res_lh = lh_src2;
    }
    if(fp16_to_float(hl_src1) > fp16_to_float(hl_src2)){
        res_hl = hl_src1;
    }else{
        res_hl = hl_src2;
    }
    if(fp16_to_float(hh_src1) > fp16_to_float(hh_src2)){
        res_hh = hh_src1;
    }else{
        res_hh = hh_src2;
    }

    uint64_t res = ((res_hh & 0xFFFF) << 48) | ((res_hl & 0xFFFF) << 32) | ((res_lh & 0xFFFF) << 16) | (res_ll & 0xFFFF);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFEXTS32L(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t low_src = src & 0xFFFFFFFF;

    uint64_t res = (low_src << 32) | low_src;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFEXTS32H(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t high_src = (src >> 32) & 0xFFFFFFFF; 

    uint64_t res = (high_src << 32) | high_src;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFEXTH16LL(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t ll_src = src & 0xFFFF; 

    uint64_t res = ((ll_src << 48) | (ll_src << 32) | (ll_src << 16) | ll_src);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFEXTH16LH(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t lh_src = (src >> 16) & 0xFFFF; 

    uint64_t res = ((lh_src << 48) | (lh_src << 32) | (lh_src << 16) | lh_src);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFEXTH16HL(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t hl_src = (src >> 32) & 0xFFFF; 

    uint64_t res = ((hl_src << 48) | (hl_src << 32) | (hl_src << 16) | hl_src);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFEXTH16HH(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t hh_src = (src >> 48) & 0xFFFF; 

    uint64_t res = ((hh_src << 48) | (hh_src << 32) | (hh_src << 16) | hh_src);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SADD32_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    int32_t low_src1 = static_cast<int32_t>(src1 & 0xFFFFFFFF);
    int32_t high_src1 = static_cast<int32_t>((src1 >> 32) & 0xFFFFFFFF);
    int32_t low_src2 = static_cast<int32_t>(src2 & 0xFFFFFFFF);
    int32_t high_src2 = static_cast<int32_t>((src2 >> 32) & 0xFFFFFFFF);

    uint64_t res = (static_cast<uint64_t>(high_src1 + high_src2) << 32) | static_cast<uint64_t>(low_src1 + low_src2);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SADD32_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);

    int32_t low_src1 = ((static_cast<int32_t>(src1) << 26) >> 26) & 0xFFFFFFFF; 
    int32_t high_src1 = low_src1;
    int32_t low_src2 = static_cast<int32_t>(src2 & 0xFFFFFFFF);
    int32_t high_src2 = static_cast<int32_t>((src2 >> 32) & 0xFFFFFFFF);

    uint64_t res = (static_cast<uint64_t>(high_src1 + high_src2) << 32) | static_cast<uint64_t>(low_src1 + low_src2);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SADDU32_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint32_t low_src1 = static_cast<uint32_t>(src1 & 0xFFFFFFFF); 
    uint32_t high_src1 = static_cast<uint32_t>((src1 >> 32) & 0xFFFFFFFF);
    uint32_t low_src2 = static_cast<uint32_t>(src2 & 0xFFFFFFFF);
    uint32_t high_src2 = static_cast<uint32_t>((src2 >> 32) & 0xFFFFFFFF);

    uint64_t res = (static_cast<uint64_t>(high_src1 + high_src2) << 32) | static_cast<uint64_t>(low_src1 + low_src2);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SADDU32_src1_imm_SMAC(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);

    uint32_t low_src1 = static_cast<uint32_t>(src1 & 0xFFFFFFFF); 
    uint32_t high_src1 = low_src1;
    uint32_t low_src2 = static_cast<uint32_t>(src2 & 0xFFFFFFFF);
    uint32_t high_src2 = static_cast<uint32_t>((src2 >> 32) & 0xFFFFFFFF);

    uint64_t res = (static_cast<uint64_t>(high_src1 + high_src2) << 32) | static_cast<uint64_t>(low_src1 + low_src2);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SADD_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    int64_t src1 = read_Reg(src1_reg_id);
    int64_t src2 = read_Reg(src2_reg_id);

    uint64_t res = src1 + src2;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SADD_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);

    int64_t src1_64 = static_cast<int64_t>((src1 << 58) >> 58);

    uint64_t res = src1_64 + static_cast<int64_t>(src2);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SADDU_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t res = src1 + src2;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SADDU_src1_imm_SMAC(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t res = src1 + src2;

    write_Reg(dst_reg_id, res, 1);
    return res;
}

// TODO：处理溢出
inline uint64_t SMAC::do_SADDA_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    
    // 取低36位
    uint64_t src1_36 = src1 & 0xFFFFFFFFF;
    int64_t signed_36 = static_cast<int64_t>(src1_36 << 28); // 左移使符号位在最高位
    signed_36 >>= 28; // 算术右移进行符号扩展
    uint64_t src1_37 = static_cast<uint64_t>(signed_36) & 0x1FFFFFFFFF;
    uint64_t src2_37 = src2 & 0x1FFFFFFFFF;

    uint64_t res = (src1_37 + src2_37) & 0xFFFFFFFFF; // 取低36位结果

    if (is_Vec_Addr_Reg(src2_reg_id)) {
        write_Reg(dst_reg_id, res, 3);
    } else {
        write_Reg(dst_reg_id, res, 2);
    }
    return res;
}

// TODO：处理溢出
inline uint64_t SMAC::do_SADDA_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);
    
    // 取低36位
    uint64_t src1_36 = src1 & 0xFFFFFFFFF;
    int64_t signed_36 = static_cast<int64_t>(src1_36 << 28); // 左移使符号位在最高位
    signed_36 >>= 28; // 算术右移进行符号扩展
    uint64_t src1_37 = static_cast<uint64_t>(signed_36) & 0x1FFFFFFFFF;
    uint64_t src2_37 = src2 & 0x1FFFFFFFFF;

    uint64_t res = (src1_37 + src2_37) & 0xFFFFFFFFF; // 取低36位结果

    if (is_Vec_Addr_Reg(src2_reg_id)) {
        write_Reg(dst_reg_id, res, 3);
    } else {
        write_Reg(dst_reg_id, res, 2);
    }
    return res;
}


inline uint64_t SMAC::do_SSUB32_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    int32_t low_src1 = static_cast<int32_t>(src1 & 0xFFFFFFFF);
    int32_t high_src1 = static_cast<int32_t>((src1 >> 32) & 0xFFFFFFFF);
    int32_t low_src2 = static_cast<int32_t>(src2 & 0xFFFFFFFF);
    int32_t high_src2 = static_cast<int32_t>((src2 >> 32) & 0xFFFFFFFF);

    uint64_t res = (static_cast<uint64_t>(high_src2 - high_src1) << 32) | static_cast<uint64_t>(low_src2 - low_src1);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SSUB32_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);

    uint32_t low_src1 = static_cast<int32_t>((src1 << 26) & 0xFFFFFFFF) >> 26; 
    uint32_t high_src1 = low_src1;
    uint32_t low_src2 = static_cast<uint32_t>(src2 & 0xFFFFFFFF);
    uint32_t high_src2 = static_cast<uint32_t>((src2 >> 32) & 0xFFFFFFFF);

    uint64_t res = (static_cast<uint64_t>(high_src2 - high_src1) << 32) | static_cast<uint64_t>(low_src2 - low_src1);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SSUBU32_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint32_t low_src1 = static_cast<uint32_t>(src1 & 0xFFFFFFFF);
    uint32_t high_src1 = static_cast<uint32_t>((src1 >> 32) & 0xFFFFFFFF);
    uint32_t low_src2 = static_cast<uint32_t>(src2 & 0xFFFFFFFF);
    uint32_t high_src2 = static_cast<uint32_t>((src2 >> 32) & 0xFFFFFFFF);

    uint64_t res = (static_cast<uint64_t>(high_src2 - high_src1) << 32) | static_cast<uint64_t>(low_src2 - low_src1);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SSUBU32_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);

    uint32_t low_src1 = static_cast<uint32_t>(src1& 0xFFFFFFFF); 
    uint32_t high_src1 = low_src1;
    uint32_t low_src2 = static_cast<uint32_t>(src2 & 0xFFFFFFFF);
    uint32_t high_src2 = static_cast<uint32_t>((src2 >> 32) & 0xFFFFFFFF);

    uint64_t res = (static_cast<uint64_t>(high_src2 - high_src1) << 32) | static_cast<uint64_t>(low_src2 - low_src1);

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SSUB_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    int64_t bits_src1 = static_cast<int64_t>(src1);
    int64_t bits_src2 = static_cast<int64_t>(src2);

    uint64_t res = bits_src2 - bits_src1;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SSUB_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);

    int64_t bits_src1 = static_cast<int64_t>((src1 << 58) >> 58);
    int64_t bits_src2 = static_cast<int64_t>(src2);

    uint64_t res = bits_src2 - bits_src1;

    write_Reg(dst_reg_id, res, 1);
    return res;
}

// 饱和操作???
inline uint64_t SMAC::do_SSUBU_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t res = src2 - src1;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SSUBU_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);
    
    uint64_t res = src2 - src1;

    write_Reg(dst_reg_id, res, 1);
    return res;
}

// 处理溢出
inline uint64_t SMAC::do_SSUBA_src1_r_SMAC(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    
    // 取低36位
    uint64_t src1_36 = src1 & 0xFFFFFFFFF;
    int64_t signed_36 = static_cast<int64_t>(src1_36 << 28); // 左移使符号位在最高位
    signed_36 >>= 28; // 算术右移进行符号扩展
    uint64_t src1_37 = static_cast<uint64_t>(signed_36) & 0x1FFFFFFFFF;
    uint64_t src2_37 = src2 & 0x1FFFFFFFFF;

    uint64_t res = (src2_37 - src1_37) & 0xFFFFFFFFF; // 取低36位结果

    if (is_Vec_Addr_Reg(src2_reg_id)) {
        write_Reg(dst_reg_id, res, 3);
    } else {
        write_Reg(dst_reg_id, res, 2);
    }

    return res;
}

// 处理溢出
inline uint64_t SMAC::do_SSUBA_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);
    
    // 取低36位
    uint64_t src1_36 = src1 & 0xFFFFFFFFF;
    int64_t signed_36 = static_cast<int64_t>(src1_36 << 28); // 左移使符号位在最高位
    signed_36 >>= 28; // 算术右移进行符号扩展
    uint64_t src1_37 = static_cast<uint64_t>(signed_36) & 0x1FFFFFFFFF;
    uint64_t src2_37 = src2 & 0x1FFFFFFFFF;

    uint64_t res = (src2_37 - src1_37) & 0xFFFFFFFFF; // 取低36位结果

    if (is_Vec_Addr_Reg(src2_reg_id)) {
        write_Reg(dst_reg_id, res, 3);
    } else {
        write_Reg(dst_reg_id, res, 2);
    }
    return res;
}


inline uint64_t SMAC::do_SMULISU32_src1_r(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);


    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF;

    uint64_t dst_e_low = static_cast<int32_t>(low32_src1 * low32_src2);
    uint64_t dst_e_high = static_cast<int32_t>(high32_src1 * high32_src2);

    uint64_t res_low = dst_e_low & 0xFFFFFFFF;
    uint64_t res_high = dst_e_high & 0xFFFFFFFF;

    uint64_t res = res_high << 32 | res_low;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SMULISU32_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);


    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF;

    uint64_t dst_e_low = static_cast<int32_t>(low32_src1 * low32_src2);
    uint64_t dst_e_high = static_cast<int32_t>(high32_src1 * high32_src2);

    uint64_t res_low = dst_e_low & 0xFFFFFFFF;
    uint64_t res_high = dst_e_high & 0xFFFFFFFF;

    uint64_t res = res_high << 32 | res_low;
    
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SMULIS32_src1_r(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);


    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF;

    uint64_t dst_e_low = static_cast<int32_t>(low32_src1) * static_cast<int32_t>(low32_src2);
    uint64_t dst_e_high = static_cast<int32_t>(high32_src1) * static_cast<int32_t>(high32_src2);

    uint64_t res_low = dst_e_low & 0xFFFFFFFF;
    uint64_t res_high = dst_e_high & 0xFFFFFFFF;

    uint64_t res = res_high << 32 | res_low;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SMULIS32_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);


    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF;

    uint64_t dst_e_low = static_cast<int32_t>(low32_src1) * static_cast<int32_t>(low32_src2);
    uint64_t dst_e_high = static_cast<int32_t>(high32_src1) * static_cast<int32_t>(high32_src2);

    uint64_t res_low = dst_e_low & 0xFFFFFFFF;
    uint64_t res_high = dst_e_high & 0xFFFFFFFF;

    uint64_t res = res_high << 32 | res_low;
    
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SMULIS_src1_r(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    __uint128_t result = static_cast<__uint128_t>(src1) * static_cast<__uint128_t>(src2);

    uint64_t res_low = static_cast<uint64_t>(result);
    uint64_t res_high = static_cast<uint64_t>(result >> 64);

    //TODO:使用res_high去对MOF溢出寄存器进行操作

    write_Reg(dst_reg_id, res_low, 3);
    return res_low;
}


inline uint64_t SMAC::do_SMULIS_src2_imm(uint64_t src1, int src2_reg_id, int dst_reg_id){
    uint64_t src2 = read_Reg(src2_reg_id);
    uint64_t src1_64 = (static_cast<int64_t>(src1) << 58) >> 58;

    __uint128_t result = static_cast<__uint128_t>(src1_64) * static_cast<__uint128_t>(src2);

    uint64_t res_low = static_cast<uint64_t>(result);
    uint64_t res_high = static_cast<uint64_t>(result >> 64);

    //TODO:使用res_high去对MOF溢出寄存器进行操作

    write_Reg(dst_reg_id, res_low, 3);
    return res_low;
}


inline uint64_t SMAC::do_SMOV(int src_reg_id, int dst_reg_id){
    // std::cout << "Entering SMOV operation" << std::endl;
    std::cout << "src_reg_id: " << src_reg_id << ", dst_reg_id: " << dst_reg_id << std::endl;
    uint64_t src = read_Reg(src_reg_id);
    uint64_t res = src;

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SMOVI(uint64_t imm, int dst_reg_id){
    uint64_t res = imm;
    std::cout << "SMOVI immediate value: " << imm << ", double representation: " << res << std::endl;

    write_Reg(dst_reg_id, res, 1);
    return res;
}













inline uint64_t SMAC::do_SFCMPED(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    double src1_d = uint64_to_double(src1);
    double src2_d = uint64_to_double(src2);

    uint64_t res;

    if(src1_d == src2_d){
        res = 1;
    }else{
        res = 0;
    }

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFCMPES32(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF;

    uint64_t low_res, high_res;
    if(uint32_to_float(low32_src1) == uint32_to_float(low32_src2)){
        low_res = 1;
    }else{
        low_res = 0;
    }
    if(uint32_to_float(high32_src1) == uint32_to_float(high32_src2)){
        high_res = 1;
    }else{
        high_res = 0;
    }

    uint64_t res = high_res << 32 | low_res;
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFCMPGD(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    uint64_t res;

    if(uint64_to_double(src1) > uint64_to_double(src2)){
        res = 1;
    }else{
        res = 0;
    }

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFCMPGS32(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF; //取高、低32位

    uint64_t low_res, high_res;
    if(uint32_to_float(low32_src1) > uint32_to_float(low32_src2)){
        low_res = 1;
    }else{
        low_res = 0;
    }
    if(uint32_to_float(high32_src1) > uint32_to_float(high32_src2)){
        high_res = 1;
    }else{
        high_res = 0;
    }

    uint64_t res = high_res << 32 | low_res;
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFCMPLD(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    uint64_t res;

    if(uint64_to_double(src1) < uint64_to_double(src2)){
        res = 1;
    }else{
        res = 0;
    }

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFCMPLS32(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);

    uint64_t low32_src1 = src1 & 0xFFFFFFFF;
    uint64_t high32_src1 = (src1 >> 32) & 0xFFFFFFFF;
    uint64_t low32_src2 = src2 & 0xFFFFFFFF;
    uint64_t high32_src2 = (src2 >> 32) & 0xFFFFFFFF; //取高、低32位

    uint64_t low_res, high_res;
    if(uint32_to_float(low32_src1) < uint32_to_float(low32_src2)){
        low_res = 1;
    }else{
        low_res = 0;
    }
    if(uint32_to_float(high32_src1) < uint32_to_float(high32_src2)){
        high_res = 1;
    }else{
        high_res = 0;
    }

    uint64_t res = high_res << 32 | low_res;
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFDINT(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);
    uint64_t res = double_to_int64(uint64_to_double(src));

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFSINT32(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t low32_src = static_cast<int32_t>(src & 0xFFFFFFFF);
    uint64_t high32_src = static_cast<int32_t>((src >> 32) & 0xFFFFFFFF);

    uint64_t res = high32_src << 32 | low32_src;

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFDTRU(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);
    uint64_t res = int64_to_double(static_cast<int64_t>(std::floor(src)));

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFSTRU32(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t low32_src = src & 0xFFFFFFFF;
    uint64_t high32_src = (src >> 32) & 0xFFFFFFFF;

    int32_t low_res, high_res;
    low_res =  float_to_int32(std::floor(uint32_to_float(low32_src)));
    high_res =  float_to_int32(std::floor(uint32_to_float(high32_src)));

    uint64_t res = static_cast<uint64_t>(high_res) << 32 | static_cast<uint64_t>(low_res);

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFINTD(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t res = double_to_uint64(int64_to_double(src));

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFINTDU(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t res = double_to_uint64(uint64_to_double(src));

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFINTS32(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t low32_src = src & 0xFFFFFFFF;
    uint64_t high32_src = (src >> 32) & 0xFFFFFFFF;

    uint64_t low_res, high_res;
    low_res = float_to_uint32(int32_to_float(low32_src));
    high_res =  float_to_uint32(int32_to_float(high32_src));

    uint64_t res = (high_res << 32) | low_res;

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFINTSU32(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    float low_src = uint32_to_float(src & 0xFFFFFFFF);
    float high_src = uint32_to_float((src >> 32) & 0xFFFFFFFF);

    uint64_t low_res, high_res;
    low_res =  float_to_uint32(low_src);
    high_res =  float_to_uint32(high_src);

    uint64_t res = (high_res << 32) | low_res;

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFDPSP32(int src1_reg_id, int src2_reg_id, int dst_reg_id){
    uint64_t src1 = read_Reg(src1_reg_id);
    uint64_t src2 = read_Reg(src2_reg_id);
    
    uint64_t res;
    uint64_t low_res, high_res;

    low_res = float_to_uint32(uint64_to_float(src1));
    high_res = float_to_uint32(uint64_to_float(src2));
    res = (high_res << 32) | low_res;

    write_Reg(dst_reg_id, res, 3);
    return res;
}


inline uint64_t SMAC::do_SFSPDP32T(int src_reg_id, int dst_reg_id){
     uint64_t src = read_Reg(src_reg_id);


    uint64_t low32_src = src & 0xFFFFFFFF;

    uint64_t res = double_to_uint64(float_to_double(uint32_to_float(low32_src)));

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFSPHDP32T(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t high32_src = (src >> 32) & 0xFFFFFFFF;

    uint64_t res = double_to_uint64(float_to_double(uint32_to_float(high32_src)));

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFMAND(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);
    
    uint64_t sign = (src >> 63) & 0x1; //提取符号位
    uint64_t mantissa = (src & 0x000FFFFFFFFFFFFF) | 0x0010000000000000; // 提取尾数（包含隐藏位）
    uint64_t res = -((sign << 63) | (mantissa << 10)); // 组合符号位和尾数，并取补码

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFMANS32(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t low32_src = src & 0xFFFFFFFF;
    uint64_t high32_src = (src >> 32) & 0xFFFFFFFF;  
    
    uint64_t low_result = fraction_32(low32_src);
    uint64_t high_result = fraction_32(high32_src);

    // 将两个32位结果组合成一个64位结果
    uint64_t res = (high_result << 32) | low_result & 0xFFFFFFFF;
   
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFLOGD(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);
    
    uint64_t exponent = (src >> 52) & 0x7FF;

        
    uint64_t res = static_cast<int64_t>(exponent) - 1023; // 减去1023（双精度浮点数的指数偏移量）

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFLOGS32(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint32_t low32_src = uint32_to_float(static_cast<uint32_t>(src & 0xFFFFFFFF));
    uint32_t high32_src = uint32_to_float(static_cast<uint32_t>((src >> 32) & 0xFFFFFFFF));
    
    uint32_t exponent_low = (src >> 23) & 0xFF;
    uint32_t exponent_high = (src >> 23) & 0xFF;
        
    uint64_t res_low = static_cast<int64_t>(exponent_low) - 127;
    uint64_t res_high = static_cast<int64_t>(exponent_low) - 127;

    uint64_t res = (res_high << 32) | (res_low & 0xFFFFFFFF);   

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFABSD(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);
    double src_d = uint64_to_double(src);

    uint64_t res = double_to_uint64(std::abs(src_d));   

    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFABSS32(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t low32_src = src & 0xFFFFFFFF;
    uint64_t high32_src = (src >> 32) & 0xFFFFFFFF;

    uint64_t res_low = float_to_uint32(std::abs(uint32_to_float(low32_src)));
    uint64_t res_high = float_to_uint32(std::abs(uint32_to_float(high32_src)));

    uint64_t res = (res_high << 32) | (res_low & 0xFFFFFFFF);
   
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFRSQD(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);
    double src_d = uint64_to_double(src);

    uint64_t res = double_to_uint64(sqrcp(src_d));
   
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFRSQS32(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t low32_src = src & 0xFFFFFFFF;
    uint64_t high32_src = (src >> 32) & 0xFFFFFFFF;

    float res_low = 1.0f / std::sqrt(uint32_to_float(low32_src));
    float res_high = 1.0f / std::sqrt(uint32_to_float(high32_src));
    uint64_t res = static_cast<uint64_t>(float_to_uint32(res_high)) << 32 | static_cast<uint64_t>(float_to_uint32(res_low) & 0xFFFFFFFF);
   
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFRCPD(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t res = double_to_uint64(1.0 / (uint64_to_double(src)));
   
    write_Reg(dst_reg_id, res, 1);
    return res;
}


inline uint64_t SMAC::do_SFRCPS32(int src_reg_id, int dst_reg_id){
    uint64_t src = read_Reg(src_reg_id);

    uint64_t low32_src = src & 0xFFFFFFFF;
    uint64_t high32_src = (src >> 32) & 0xFFFFFFFF;

    float res_low = 1.0f / uint32_to_float(low32_src);
    float res_high = 1.0f / uint32_to_float(high32_src);
    uint64_t res = (static_cast<uint64_t>(float_to_uint32(res_high)) << 32 | static_cast<uint64_t>((float_to_uint32(res_low) & 0xFFFFFFFF)));
   
    write_Reg(dst_reg_id, res, 1);
    return res;
}

inline uint64_t SMAC::do_SVBCAST(int src_reg_id, int dst_reg_id) {
    uint64_t src = read_Reg(src_reg_id);
    uint64_t res = src;  // Simple broadcast: replicate the value
    write_Reg(dst_reg_id, res, 4);
    return res;
}

write_req_info_reg  SMAC::upload_write_msg() {
    write_req_info_reg res;
    res.value = this->res_value;
    res.reg_id = this->dst_reg_id;
    res.delay = this->delay_cycles;
    return res;
}



//TODO:与控制指令的交互
uint64_t SMAC::Execute(instruction* smac_instr) {
    //需要根据控制指令来执行具体的计算逻辑（类似ALU）
    // double dst = 0.0; 
    std::cout << "SMAC executing instruction with opcode: " << smac_instr->get_opcode() << std::endl;
    // return dst;
    switch (smac_instr->get_opcode()) {
        case SFMULD:
            return do_SFMULD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());                                    
        case SFMULS32:
            return do_SFMULS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());           
        case SFMULAD:
            return do_SFMULAD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(3))->get_reg_id());          
        case SFMULAS32:
            return do_SFMULAS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(3))->get_reg_id());                               
        case SFMULBD:
            return do_SFMULBD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(3))->get_reg_id());                                
        case SFMULBS32:
            return do_SFMULBS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(3))->get_reg_id());                               
        case SFDOT32:
            return do_SFDOT32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());                             
        case SFCREAL32:
            return do_SFCREAL32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());    
        case SFCIMAG32:
            return do_SFCIMAG32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SFADDH16:
            return do_SFADDH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());     
        case SFSUBH16:
            return do_SFSUBH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());  
        case SFMULH16:
            return do_SFMULH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());   
        case SFMULAH16:
            return do_SFMULAH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(3))->get_reg_id());  
        case SFMULBH16:
            return do_SFMULBH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(3))->get_reg_id());
            
        case SFCMPEH16:
            return do_SFCMPEH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
            
        case SFCMPGH16:
            return do_SFCMPGH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());  
        case SFCMPLH16:
            return do_SFCMPLH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());   
        case SFHINT16:
            return do_SFHINT16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());  
        case SFHTRU16:
            return do_SFHTRU16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());          
        case SFINTH16:
            return do_SFINTH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());          
        case SFINTHU16:
            return do_SFINTHU16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());           
        case SFSPHP16:
            return do_SFSPHP16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());        
        case SFHPSP16L:
            return do_SFHPSP16L(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());       
        case SFHPSP16H:
            return do_SFHPSP16H(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());           
        case SFMANH16:
            return do_SFMANH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());        
        case SFLOGH16:
            return do_SFLOGH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());       
        case SFABSH16:
            return do_SFABSH16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id()); 
        case SFMAX16:
            return do_SFMAX16(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());       
        case SFEXTS32L:
            return do_SFEXTS32L(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id()); 
        case SFEXTS32H:
            return do_SFEXTS32H(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());  
        case SFEXTH16LL:
            return do_SFEXTH16LL(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());  
        case SFEXTH16LH:
            return do_SFEXTH16LH(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id()); 
        case SFEXTH16HL:
            return do_SFEXTH16HL(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFEXTH16HH:
            return do_SFEXTH16HH(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SADD32_src1_r_SMAC:
            return do_SADD32_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SADD32_src2_imm:
            return do_SADD32_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                    static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SADDU32_src1_r_SMAC:
            return do_SADDU32_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id()); 
        case SADDU32_src1_imm_SMAC:
            return do_SADDU32_src1_imm_SMAC(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SADD_src1_r_SMAC:
            return do_SADD_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SADD_src2_imm:
            return do_SADD_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SADDU_src1_r_SMAC:
            return do_SADDU_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SADDU_src1_imm_SMAC:
            return do_SADDU_src1_imm_SMAC(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SADDA_src1_r_SMAC:
            return do_SADDA_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SADDA_src2_imm:
            return do_SADDA_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SSUB32_src1_r_SMAC:
            return do_SSUB32_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SSUB32_src2_imm:
            return do_SSUB32_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SSUBU32_src1_r_SMAC:
            return do_SSUBU32_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                                static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SSUBU32_src2_imm:
            return do_SSUBU32_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SSUB_src1_r_SMAC:
            return do_SSUB_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SSUB_src2_imm:
            return do_SSUB_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SSUBU_src1_r_SMAC:
            return do_SSUBU_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SSUBU_src2_imm:
            return do_SSUBU_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SSUBA_src1_r_SMAC:
            return do_SSUBA_src1_r_SMAC(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
            
        case SSUBA_src2_imm:
            return do_SSUBA_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SMULISU32_src1_r:
            return do_SMULISU32_src1_r(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SMULISU32_src2_imm:
            return do_SMULISU32_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SMULIS32_src1_r:
            return do_SMULISU32_src1_r(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SMULIS32_src2_imm:
            return do_SMULISU32_src2_imm(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                        static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                            static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());

        //TODO:补全SMULIS指令的实现
        case SMULIS_src1_r:

        case SMULIS_src2_imm:

            













        case SMOV_SMAC:
            std::cout << "Executing SMOV_SMAC instruction." << std::endl;
            return do_SMOV(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SMOVI_SMAC:
            std::cout << "Executing SMOVI_SMAC instruction." << std::endl;
            return do_SMOVI(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFCMPED:
            return do_SFCMPED(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SFCMPES32:
            return do_SFCMPES32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SFCMPGD:
            return do_SFCMPGD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SFCMPGS32:
            return do_SFCMPGS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SFCMPLD:
            return do_SFCMPLD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SFCMPLS32:
            return do_SFCMPLS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SFDINT:
            return do_SFDINT(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFSINT32:
            return do_SFSINT32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFDTRU:
            return do_SFDTRU(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFSTRU32:
            return do_SFSTRU32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFINTD:
            return do_SFINTD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFINTDU:
            return do_SFINTDU(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFINTS32:
            return do_SFINTS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFINTSU32:
            return do_SFINTSU32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFDPSP32:
            return do_SFDPSP32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id(),
                                    static_cast<register_operand*>(smac_instr->get_operands(2))->get_reg_id());
        case SFSPDP32T:
            return do_SFSPDP32T(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFSPHDP32T:
            return do_SFSPHDP32T(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFMAND:
            return do_SFMAND(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFMANS32:
            return do_SFMANS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFLOGD:
            return do_SFLOGD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SFLOGS32:
            return do_SFLOGS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());      
        case SFABSD:
            return do_SFABSD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());           
        case SFABSS32:
            return do_SFABSS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());            
        case SFRSQD:
            return do_SFRSQD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());           
        case SFRSQS32:
            return do_SFRSQS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());           
        case SFRCPD:
            return do_SFRCPD(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());          
        case SFRCPS32:
            return do_SFRCPS32(static_cast<register_operand*>(smac_instr->get_operands(0))->get_reg_id(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());
        case SVBCAST:
            std::cout << "Executing SVBCAST instruction." << std::endl;
            return do_SVBCAST(static_cast<immediate_operand*>(smac_instr->get_operands(0))->get_imme_value(),
                                static_cast<register_operand*>(smac_instr->get_operands(1))->get_reg_id());        
        //TODO:将所有操作的实际执行逻辑补全
        //TODO:SMVAGA，SMVAAG，SMVAAA...等指令的实现
    }
}
